package com.dundun.pattern.strategy;

public class Hand {
    public static final int GUU = 0;
    public static final int CHO = 1;
    public static final int PAA = 2;
    private static final Hand[] hand = {
            new Hand(GUU),
            new Hand(CHO),
            new Hand(PAA)
    };
    private static final String[] name = {"石头","剪刀","布"};
    private int value;
    private Hand(int value) {
        this.value = value;
    }
    public static Hand getHand(int value) {
        return hand[value];
    }
    public boolean isStrongerThan(Hand h) {
        return fight(h) == 1;
    }
    public boolean isWeakerThan(Hand h) {
        return fight(h) == -1;
    }
    private int fight(Hand h) {
        if(this == h) {
            return 0;
        } else if((this.value + 1)%3 == h.value) {
            return 1;
        } else {
            return -1;
        }
    }

    @Override
    public String toString() {
        return name[value];
    }
}
